#include "dboptview.h"
#include <QHeaderView>

DBOptView::DBOptView(QWidget *parent) :
    QWidget(parent)
    ,mTableMove(NULL)
{
    mTab.setParent(this);
    mTab.move(0,0);
    mTab.resize(this->width(),this->height());
    //mTab.setStyleSheet();
    mTab.verticalHeader()->setVisible(false);     //隐藏序号列
    mTab.setSelectionBehavior(QAbstractItemView::SelectRows); //设置点击选择方式，行、列、单元格
    mTab.setSelectionMode(QAbstractItemView::MultiSelection); //设置可选择条目数
    mTab.setEditTriggers(QAbstractItemView::NoEditTriggers);  //内容不可编辑
    mTab.horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);   //设置表头不可拖动
    mTab.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //去掉水平滚动条
    //ui->tableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //去掉垂直滚动条

}

void DBOptView::setMoveEnable(bool flag)
{
    if(flag)
    {
        if(mTableMove == NULL)
            mTableMove = new CustomScroll(&mTab,this);
    }
    else
    {
        if(mTableMove != NULL)
        {
            delete mTableMove;
            mTableMove = NULL;
        }
    }
}

void DBOptView::setShowModel(QString dbName)    //切换表格显示
{
    mTab.setModel(mDB.getTableModel(dbName));
    mTab.show();
}

bool DBOptView::loadDB(QString dbName, QString dbType)  //导入数据库
{
    return mDB.open(dbName,dbType);
}

bool DBOptView::creatTab(QString tabStruct)     //创建表格
{
    return mDB.creatTab(tabStruct);
}

bool DBOptView::deleteTab(QString tabName)  //删除表格
{
    return mDB.deleteTab(tabName);
}

QStringList DBOptView::getTabNames()        //获取所有表格名字
{
    return mDB.getTableNames();
}

QStringList DBOptView::getHeaderList(QString tabName)   //获取表格段名字
{
    return mDB.getTableIndexName(tabName);
}

void DBOptView::resizeEvent(QResizeEvent *event)
{
    mTab.resize(this->width(),this->height());
}



